package com.engine.jucailinkq.attendance.component.persongroup.job.scheduling;

import com.engine.jucailinkq.attendance.component.persongroup.job.scheduling.tactics.RegularScheduling;
import com.engine.jucailinkq.common.util.DateUtil;
import com.engine.jucailinkq.common.util.DbTools;
import com.engine.jucailinkq.common.util.Utils;

import lombok.extern.slf4j.Slf4j;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;

import java.util.List;
import java.util.Map;

@Slf4j
public class SchedulingJob extends BaseCronJob {

    /**
     * 生成天数
     */
    private String day;
    private List<RegularScheduling> rulers;
    {
        rulers = new Utils<RegularScheduling>().getAllClassByInterface(RegularScheduling.class);

    }
    @Override
    public void execute() {
        String useDate = com.time.util.DateUtil.getCurrentTime("yyyy-MM-dd");
        String sql = "select * from uf_jcl_kq_glpb where edate > ? and bdate<=?";
        List<Map<String,Object>> dataList = DbTools.getSqlToList(sql,useDate,useDate);
        Map<String,String> formmodeIdMap = Utils.getFormmodeIdMap();
        //规律排班模块id
        String modeId = formmodeIdMap.get("uf_jcl_kq_glpb");
        //排班结果模块
        String formmodeid = formmodeIdMap.get("uf_pbjg");
        log.debug("dataList : [{}]",dataList);
        try {
            dataList.forEach(e -> {
                e.put("modeId",modeId);
                e.put("day",day);
                e.put("formmodeid",formmodeid);
                e.put("executeDate", DateUtil.getCurrentDate());
                String zzqlx = Util.null2String(e.get("zzqlx"));
                for (RegularScheduling workOverTimeComputeRuler :rulers){
                    if (workOverTimeComputeRuler.support(Integer.valueOf(zzqlx))){
                        workOverTimeComputeRuler.compute(e);
                    }
                }
            });
        }catch (Exception e){
            log.error("catch error: [{}]",e);
        }
    }
}
